{% extends 'base.html' %}
{% block title %}
博客详情
{% endblock %}
{% block main %}
    <h1>{{ blog.title }}</h1>
    <div class="mt-2">
        <img src="{% static 'image/avatar.jpg' %}" class="rounded-circle" width="30" height="30">
        <span class="ms-2">{{ blog.author }}</span>
        <span class="ms-2">于</span>
        <span class="ms-2">{{ blog.pub_time | date:"Y年m月d日 H:i" }}</span>发布
    </div>
    <hr>
    <div class="py-2">
       {{ blog.content |safe }}
    </div>
    <hr>
    <div class="mt-2">
        <h3>评论({{ blog.comments.all|length }})</h3>
        <form action="/blog/comment/pub" method="POST">

            {% csrf_token %}
            <input type="hidden" name="blog_id" value="{{ blog.id }}">
            <div class="mt-2">
                <input type="text" name="content" class="form-control" placeholder="请输入评论内容">
            </div>
            <div class="text-end mt-2">
                <button class="btn btn-primary" type="submit">评论</button>
            </div>
        </form>
    </div>

    <div class="mt-2">
        <ul class="list-group list-group-flush">
            {% for comment in blog.comments.all %}

            <li class="list-group-item">
                <div class="d-flex justify-content-between text-body-secondary">
                    <div class="user-info">
                        <img src="{% static 'image/avatar.jpg' %}" class="rounded-circle" width="40" height="40">
                        <span class="ms-2">{{ comment.author.username }}</span>
                    </div>
                    <div class="create-time" style="line-height: 40px">{{ comment.pub_time | date:"Y年m月d日 H:i" }}</div>
                </div>
                <div class="mt-2">{{ comment.content }}</div>
            </li>
            {% endfor %}
        </ul>
    </div>
    <hr>
{% endblock %}